#ifndef _NE_ANIMATION_TRACK_H_
#define _NE_ANIMATION_TRACK_H_

#include <animation/KeyFrame.h>

namespace ne
{
    class Animation;

    class NEAPI AnimationTrack
    {
        public:
            AnimationTrack(Animation *parent, const uint16_t handle);

            uint16_t getHandle() const;

            virtual KeyFrame* createKeyFrame(const real time);

            virtual bool destroyKeyFrame(const size_t index);

            virtual void destroyAllKeyFrames();

            virtual size_t getKeyFramesCount() const;

            virtual KeyFrame* getKeyFrame(const size_t index) const;

            virtual void getKeyFrameAtTime(const real time, KeyFrame &keyFrame) const = 0;

            virtual void apply(const real time, const real weight=1.0, const real scaleU=1.0f) = 0;

            virtual const KeyFrameVector& getKeyFrameVector() const;

            virtual void _keyFrameDataChanged() const;

            virtual ~AnimationTrack();

        protected:
            virtual KeyFrame* _createKeyFrameImpl(const real time) = 0;

            virtual void _needSort() const;

            virtual void _sort() const;

            virtual void _binarySearchKeyFramesAtTime(size_t begin, size_t end, const real time, KeyFrame **beginKeyFrame, KeyFrame **endKeyFrame) const;

        public:
            static bool KeyFrameLess(const KeyFrame *keyA, const KeyFrame *keyB);

        private:
            AnimationTrack();

            AnimationTrack(const AnimationTrack &);

            AnimationTrack& operator = (const AnimationTrack &);

        public:
            static const uint16_t MAX_ANIMATION_TRACK_HANDLE;

        protected:
            uint16_t mHandle;
            Animation *mpParentAnimation;
            mutable KeyFrameVector mKeyFrames;
            mutable bool mNeedSort;
    };
}

#endif
